

<?php
if ($this->code == "0"){
    //echo "<legend>";
    echo $this->msg;
    //echo "</legend>";
}else echo $this->msg;

if ($this->code == ""){
?>

<form method="post" id="frmAdd" name="frmAdd">
<legend>Pendaftaran Member</legend>
<div class="row clearfix">
    <div class="col-md-6 column">
        
        <h4>Member Detail</h4>

        <div class="form-group">
                 <label for="sponsor_code">Introducer</label>
                 <input id="sponsor_code" name="sponsor_code" type="text" placeholder="Sponsor"
                class="form-control" readonly value="<?php echo (isset($this->sess["member_code"])) ? $this->sess["member_code"] : ""; ?>">
                <input type="hidden" name="sponsor_id" id="sponsor_id" value="<?php echo (isset($this->sess["member_id"])) ? $this->sess["member_id"] : ""; ?>">
        </div>
        
    </div>
    <div class="col-md-6 column">

    </div>
</div>

<div class="row clearfix">
    <div class="col-md-6 column">
        
        <div class="form-group">
                 
                 <select id="member_type_id" name="member_type_id" class="form-control">
                     <option value="">Pilih Tipe Member</option>
                    <?php
                   foreach ($this->memberTypeList as $oMemberType) {
                       if (isset($this->data["member_type_id"]) && $this->data["member_type_id"] == $oMemberType['member_type_id'])
                            echo "<option value='".$oMemberType['member_type_id']."' selected>[". $oMemberType['member_type_name'] ."] ". $oMemberType['member_type_desc'] ."</option>";
                       else
                            echo "<option value='".$oMemberType['member_type_id']."'>[". $oMemberType['member_type_name'] ."] ". $oMemberType['member_type_desc'] ."</option>";
                   }
                   ?>
                </select>
        </div>
        <div class="form-group">
                 
                 <input id="member_name" name="member_name" type="text" placeholder="Nama Member" onchange="$('#contact_name').val(this.value);$('#account_name').val(this.value)"
                 class="form-control" required value="<?php echo (isset($this->data["member_name"])) ? $this->data["member_name"] : ""; ?>">
        </div>
    </div>
    <div class="col-md-6 column">
        
        <div class="form-group">
                 
                 <input id="member_code" name="member_code" type="text" placeholder="Kode Member"
                 class="form-control" required value="<?php echo (isset($this->data["member_code"])) ? $this->data["member_code"] : ""; ?>">
        </div>

        <div class="form-group">
            
            <div class="controls">
                <input id="pin" name="pin" type="text" placeholder="PIN" class="form-control" required value="<?php echo (isset($this->data["pin"])) ? $this->data["pin"] : ""; ?>">
                <p class="help-block"></p>
            </div>
        </div>


    </div>
</div>

<!--ALAMAT MEMBER -->
<br>
<div class="row clearfix">
    <div class="col-md-6 column">
        <h4>Alamat Member</h4>

        <!-- address-line1 input-->
        <div class="form-group">
                     
            <input id="address_line1" name="address_line1" type="text" placeholder="Perumahan, Jalan, Blok, Nomor, RT/RW"
            class="form-control" required value="<?php echo (isset($this->data["address_line1"])) ? $this->data["address_line1"] : ""; ?>">
            <p class="help-block"></p>
            
        </div>
        <!-- address-line2 input-->
        <div class="form-group">
            
                <input id="address_line2" name="address_line2" type="text" placeholder="Kelurahan, Kecamatan"
                class="form-control" required value="<?php echo (isset($this->data["address_line2"])) ? $this->data["address_line2"] : ""; ?>">
                        
        </div>
        <!-- city input-->
        <div class="form-group">
            
                <input id="city" name="city" type="text" placeholder="Kota" class="form-control" required value="<?php echo (isset($this->data["city"])) ? $this->data["city"] : ""; ?>">
                            
        </div>
    </div>

    <div class="col-md-6 column">
        <h4>&nbsp;</h4>
        <!-- region input-->
        <div class="form-group">
                   
                <input id="region" name="region" type="text" placeholder="Provinsi"
                class="form-control" required value="<?php echo (isset($this->data["region"])) ? $this->data["region"] : ""; ?>">
                
        </div>
        <!-- postal-code input-->
        <div class="form-group">
            
                <input id="postal_code" name="postal_code" type="text" placeholder="Kode Pos"
                class="form-control" value="<?php echo (isset($this->data["postal_code"])) ? $this->data["postal_code"] : ""; ?>">
               
        </div>
        <!-- country select -->
        <div class="form-group">
            
                <select id="country" name="country" class="form-control" required>
                    <option value="">Pilih Negara</option>
                    <?php
                   foreach ($this->countryList as $oCountry) {
                       if ($this->data["country"] == $oCountry['code'] || $oCountry['code'] == 'ID')
                        echo "<option value='".$oCountry['code']."' selected>". $oCountry['name'] ."</option>";
                       else
                        echo "<option value='".$oCountry['code']."'>". $oCountry['name'] ."</option>";
                   }
                   ?>
                </select>
            
        </div>
    </div>
</div>

<!--KONTAK MEMBER -->
<br>
<div class="row clearfix">
    <div class="col-md-6 column">
        <h4>Kontak Member</h4>

        <!-- contact_name input-->
        <div class="form-group">
            
                <input id="contact_name" name="contact_name" type="text" placeholder="Nama Kontak"
                class="form-control" required value="<?php echo (isset($this->data["contact_name"])) ? $this->data["contact_name"] : ""; ?>">
                
        </div>
        <!-- mobile_no input-->
        <div class="form-group">
            
                <input id="mobile_no" name="mobile_no" type="text" placeholder="No HP"
                class="form-control" required value="<?php echo (isset($this->data["mobile_no"])) ? $this->data["mobile_no"] : ""; ?>">
                
        </div>
        <!-- phone input-->
        <div class="form-group">
            
                <input id="phone" name="phone" type="text" placeholder="No Tlp"
                class="form-control" value="<?php echo (isset($this->data["phone"])) ? $this->data["phone"] : ""; ?>">
                
        </div>
        <!-- email input-->
        <div class="form-group">

                <input id="email" name="email" type="text" placeholder="Email" required
                class="form-control" value="<?php echo (isset($this->data["email"])) ? $this->data["email"] : ""; ?>">

        </div>
        <!-- no_ktp input-->
        <div class="form-group">

                <input id="no_ktp" name="no_ktp" type="text" placeholder="Nomor KTP" required
                class="form-control" value="<?php echo (isset($this->data["no_ktp"])) ? $this->data["no_ktp"] : ""; ?>">

        </div>

    </div>

    <div class="col-md-6 column">
        <h4>Ahli Waris</h4>
        
        <!-- contact_name input-->
        <div class="form-group">
            
                <input id="waris_name" name="waris_name" type="text" placeholder="Nama Ahli Waris"
                class="form-control" value="<?php echo (isset($this->data["waris_name"])) ? $this->data["waris_name"] : ""; ?>">
                
        </div>
        <!-- mobile_no input-->
        <div class="form-group">
            
                <input id="waris_mobile_no" name="waris_mobile_no" type="text" placeholder="No HP Ahli Waris"
                class="form-control" value="<?php echo (isset($this->data["waris_mobile_no"])) ? $this->data["waris_mobile_no"] : ""; ?>">
                
        </div>
        <!-- phone input-->
        <div class="form-group">
            
                <input id="waris_phone" name="waris_phone" type="text" placeholder="No Tlp Ahli Waris"
                class="form-control" value="<?php echo (isset($this->data["waris_phone"])) ? $this->data["waris_phone"] : ""; ?>">
                
        </div>
        <!-- email input-->
        <div class="form-group">

                <input id="waris_email" name="waris_email" type="text" placeholder="Email Ahli Waris" 
                class="form-control" value="<?php echo (isset($this->data["waris_email"])) ? $this->data["waris_email"] : ""; ?>">

        </div>
        <!-- no_ktp input-->
        <div class="form-group">

                <input id="waris_ktp" name="waris_ktp" type="text" placeholder="Nomor KTP Ahli Waris" 
                class="form-control" value="<?php echo (isset($this->data["no_ktp"])) ? $this->data["no_ktp"] : ""; ?>">

        </div>

    </div>
</div>

<!--AKUN BANK -->
<br>
<div class="row clearfix">
    <div class="col-md-6 column">
        <h4>Akun Bank</h4>

        <!-- bank_name input-->
        <div class="form-group">
            
                <select name="bank_name" id="bank_name" class="form-control">
                    <option value="">Pilih Nama Bank</option>
                    <option value="BCA" <?php echo (isset($this->data["bank_name"]) && $this->data["bank_name"] == "BCA") ? "selected" : ""; ?>>BCA</option>
                    <option value="Mandiri" <?php echo (isset($this->data["bank_name"]) && $this->data["bank_name"] == "Mandiri") ? "selected" : ""; ?>>Mandiri</option>
                    <option value="BRI" <?php echo (isset($this->data["bank_name"]) && $this->data["bank_name"] == "BRI") ? "selected" : ""; ?>>BRI</option>
                    <option value="BNI" <?php echo (isset($this->data["bank_name"]) && $this->data["bank_name"] == "BNI") ? "selected" : ""; ?>>BNI</option>
                </select>
        </div>
        <!-- account_name input-->
        <div class="form-group">
            
                <input id="account_name" name="account_name" type="text" placeholder="Nama Akun"
                class="form-control" required value="<?php echo (isset($this->data["account_name"])) ? $this->data["account_name"] : ""; ?>">
                
        </div>
    </div>

    <div class="col-md-6 column">
        <h4>&nbsp;</h4>

        <!-- bank_account_no input-->
        <div class="form-group">
            
                <input id="bank_account_no" name="bank_account_no" type="text" placeholder="Nomor Rekening"
                class="form-control" required value="<?php echo (isset($this->data["bank_account_no"])) ? $this->data["bank_account_no"] : ""; ?>">
              
        </div>
        <!-- bank_city input-->
        <div class="form-group">
            
                <input id="bank_city" name="bank_city" type="text" placeholder="Kota Bank"
                class="form-control" required value="<?php echo (isset($this->data["bank_city"])) ? $this->data["bank_city"] : ""; ?>">
              
        </div>
    </div>
</div>
<!-- submit btn-->
                <div class="control-group">
                    <label class="control-label"></label>
                    <div class="controls">
                        <button class="btn btn-default" type="submit" id="btnSubmit" name="btnSubmit">
                        Submit</button> <div id="div_result"></div>
                        <p class="help-block"></p>
                    </div>
                </div>
</form>



        <script>

        /* Attach a submit handler to the form */
        $("#frmAdd").submit(function(event) {

            /* Stop form from submitting normally */
            event.preventDefault();

            /* Clear result div*/
            $("#div_result").html('');
            $("#btnSubmit").html('Memproses...');
            $("#btnSubmit").attr('disabled','disabled');

            /* Get some values from elements on the page: */
            var values = $(this).serialize();

            var msg = [];

            /* Send the data using post and put the results in a div */

            $.ajax({
                url: "add/",
                type: "post",
                data: values,
                success: function(response, opts){
                    var cekSess = response.toUpperCase().search("SESSION TIMEOUT");

                    if (cekSess < 0){
                        var cekStatus = response.toUpperCase().search("ERROR");

                        if (cekStatus < 0){
                            $("#div_content").html(response);
                        }else{

                            var resp = response.replace('ERROR', '');

                            msg.push('<span>'+resp+'</span>');
                            $.messager.alert('Info', msg.join('<br/>'));

                            //$("#div_result").html(resp);
                            $("#btnSubmit").removeAttr('disabled');
                            $("#btnSubmit").html('Submit');
                        }
                    }else{
                        location.href='<?php echo $this->baseUrl() ?>/index/login/msg/Session Timeout silahkan login kembali !';
                    }
                },
                error:function(response, opts){
                    //alert("failure");
                    //$("#div_result").html(response);
                    msg.push('<span>'+response+'</span>');
                    $.messager.alert('Info', msg.join('<br/>'));

                    $("#btnSubmit").removeAttr('disabled');
                }
            });

        });

        </script>

        <?php } ?>
    